#include <windows.h>

// ================================================================================================
// Simple clear screen function for windows
// ================================================================================================
void ClearScreen() {
    HANDLE                     csout; 
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    DWORD                      count;
    DWORD                      cellcount;
    COORD                      homecoords = { 0, 0 };

    csout = GetStdHandle(STD_OUTPUT_HANDLE);
    if (csout == INVALID_HANDLE_VALUE) return;

    // -- get the number of cells in the current buffer
    if (!GetConsoleScreenBufferInfo(csout, &csbi)) 
        return;

    cellcount = csbi.dwSize.X *csbi.dwSize.Y;

    // -- fill the entire buffer with spaces
    //if (!FillConsoleOutputCharacter(csout, (TCHAR)' ', cellcount, homecoords, &count )) 
    //    return;

    // -- fill the entire buffer with the current colors and attributes
    if (!FillConsoleOutputAttribute(csout, csbi.wAttributes, cellcount, homecoords, &count)) 
        return;

    // -- move the cursor home
    SetConsoleCursorPosition(csout, homecoords);
}
